
<!-- <div id="flashContent"> -->
<!-- 			<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="810" height="680" id="loader" align="middle"> -->
<!-- 				<param name="movie" value="loader.swf" /> -->
<!-- 				<param name="quality" value="high" /> -->
<!-- 				<param name="bgcolor" value="#333333" /> -->
<!-- 				<param name="play" value="true" /> -->
<!-- 				<param name="loop" value="true" /> -->
<!-- 				<param name="wmode" value="window" /> -->
<!-- 				<param name="scale" value="showall" /> -->
<!-- 				<param name="menu" value="true" /> -->
<!-- 				<param name="devicefont" value="false" /> -->
<!-- 				<param name="salign" value="" /> -->
<!-- 				<param name="allowScriptAccess" value="sameDomain" /> -->
				<!--[if !IE]>-->
<!-- 				<object type="application/x-shockwave-flash" data="loader.swf" width="810" height="680"> -->
<!-- 					<param name="movie" value="loader.swf" /> -->
<!-- 					<param name="quality" value="high" /> -->
<!-- 					<param name="bgcolor" value="#333333" /> -->
<!-- 					<param name="play" value="true" /> -->
<!-- 					<param name="loop" value="true" /> -->
<!-- 					<param name="wmode" value="window" /> -->
<!-- 					<param name="scale" value="showall" /> -->
<!-- 					<param name="menu" value="true" /> -->
<!-- 					<param name="devicefont" value="false" /> -->
<!-- 					<param name="salign" value="" /> -->
<!-- 					<param name="allowScriptAccess" value="sameDomain" /> -->
				<!--<![endif]-->
<!-- 					<a href="http://www.adobe.com/go/getflash"> -->
<!-- 						<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /> -->
<!-- 					</a> -->
				<!--[if !IE]>-->
<!-- 				</object> -->
				<!--<![endif]-->
<!-- 			</object> -->
<!-- </div> -->


<div id="flashContent">
	<a href="http://www.adobe.com/go/getflash">
		<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
	</a>
</div>



<script type="text/javascript">

function getPermission()
{	
	var permissions = "email,publish_actions,user_birthday,user_photos";
	console.log(permissions);	
 	FB.login(function(response) {
		if (response.status === 'connected') {					
			FB.api('/me?fields=id,name,picture,email,birthday,first_name,last_name',function (result) {
				
//				$.post(root_dir + 'member/login/', {"fbid": result.id, "name": result.name, "email": result.email, "birthday": result.birthday,"accessToken":response.authResponse.accessToken}, function (data) {
//					var obj = document.getElementById("my_flash");
//					obj.getPermissionComplete(data);	
//				 },"json")

				console.log("Goi ham getPermission");
				$.post('index.php?home/mirinda/insert', {"fbid": result.id, "name": result.name, "first_name": result.first_name, "last_name": result.last_name, "email": result.email, "birthday": result.birthday,"accessToken":response.authResponse.accessToken}, function (data) {
					var obj = document.getElementById("flashContent");
					obj.getPermissionComplete(data);
					console.log(data);
				 })				 
				 
			});					
		}else{
			var obj = document.getElementById("my_flash");
			obj.getPermissionCanceled();
		}
	}, {scope:permissions});
}
        
		
function login(){
	FB.login(function (response) {
		if(response.authResponse == null){
			login();
		}else if (response.authResponse.userID != "") {
		//if (response.authResponse.userID != ""){
			var facebook_id = response.authResponse.userID;
			FB.api('me', function (response) {
				console.log(response);
				if(response.error != null){
					login();
				}else{

					fbname = response.name;
					fbid = facebook_id;
					fbemail = response.email;
					
					var obj = document.getElementById("my_flash");
					obj.facebookLogin(fbname,fbid,fbemail);	
					//registration(fbid,fbemail);																																																				
				}
			});
		}
	}, { scope: 'user_photos, email, publish_stream' });
}
									
function process(){
	FB.login(function (response) {
		if(response.authResponse == null){
			process();
		}else if (response.authResponse.userID != "") {
		//if (response.authResponse.userID != ""){
			var facebook_id = response.authResponse.userID;
			getPhoto();
			/*FB.api('me', function (response) {
				console.log(response);
				if(response.error != null){
					process();
				}else{

					fbname = response.name;
					fbid = facebook_id;
					fbemail = response.email;																																																
				}
			});*/
		}
	}, { scope: 'user_photos, email, publish_stream' });
}

function registration(id, email){
	$.post("./index.php/meta/data/save_profile", {"id": id, "email": email}, function(data){
	});
}
			
function getPhoto(){
	FB.api({method: 'fql.multiquery',
			queries: {
						query1: 'SELECT name, object_id, cover_object_id  FROM album WHERE owner = me() AND photo_count > 0 ',
						query2: 'SELECT pid, src_big, src  FROM photo WHERE album_object_id  IN (SELECT object_id FROM #query1)',
						/*query3: 'SELECT name, object_id, cover_object_id  FROM album WHERE owner = me() AND photo_count > 0 AND name = "Cover Photos"',
						query4: 'SELECT pid, src_big FROM photo WHERE album_object_id  IN (SELECT object_id FROM #query3)', AND name <> "Cover Photos"*/
					}
			},
			function(response){
				console.log(response);
				var resultQuery2 = response[1].fql_result_set;							
				var totalImg = resultQuery2.length;
				
				for(var i = 0; i < totalImg; i++){
					resultQuery2[i].src_big = resultQuery2[i].src_big.replace("https://", "http://");
				}
				console.log("return flash");
				console.log(resultQuery2);
				var obj = document.getElementById("my_flash");
				obj.getFacebook(resultQuery2);
						
				/*$.post("./index.php/game/updateCover", {"cover": cover, "totalImg": totalImg}, function(data){
					if(data == 1){
						var obj = document.getElementById("my_flash");
						obj.getFacebook(resultQuery2);
					}
				});*/
				
			});
}
			
function shareFacebook(videoID, id, op) 
{
	var url = videoID > 0 ? siteUrl + '#/action?id=5&videoID=' + videoID : siteUrl + "#/discovery?videoID=" + id + "&optionID=" + op;
	// calling the API ...
	var obj = {
		method: 'feed',
		link: url, // Url come back
		picture: siteUrl + "template/Default/images/Fb_thumbnail.jpg", // Hinh share
		name: 'Name share',
		caption: '',
		message: '', //   
		description: 'test descript.'
	};

	function callback(response) {
		//console.log(response);
		var result =  response != null ? 1 : 0;
		var obj = document.getElementById("my_flash");
		obj.shareFn(result);
		return false;
	}

	FB.ui(obj, callback);
}
			
</script>
		
<script type="text/javascript">

	var flashvars = {path:"", username:"<?php echo $fullname; ?>", user_id:"<?php echo $currentFbID;?>", avatar:"http://graph.facebook.com/<?php echo $currentFbID; ?>/picture?type=large", register:"<?php echo $register; ?>", email:"<?php echo $email; ?>", total_point:"<?php echo $total_point; ?>"};
	
	var params = {bgcolor:"#fff", allowfullscreen:"true", allowscriptaccess: "always", quality: "high", play: "true", loop: "true", wmode: "window", scale: "showall", menu: "true", devicefont: "false", salign: ""};
	var attributes = {id: "flashContent", name: "flashContent"};
	
	//swfobject.embedSWF("main.swf", "flashContent", "810", "680", "8.0.0", "", flashvars, params, attributes);	
	//swfobject.embedSWF("loader.swf", "flashContent", "810", "680", "8.0.0", "", flashvars, params, attributes);
	swfobject.embedSWF("loader.swf", "flashContent", "810", "673", "8.0.0", "", flashvars, params, attributes);	
	//swffit.fit("flashContent", 810, 680 );
	
</script>


		
